<template>
  <div class="dashboard-container">
    <div class="dashboard-text">name: {{ name }}</div>
    <!-- <qrcode-vue :value="value" :size="size" level="H"></qrcode-vue> -->
    <UploadImage></UploadImage>
    <input ref="fileRef" type="file" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import UploadImage from '@/components/UploadImage/index.vue'
// import QrcodeVue from 'qrcode.vue'
var COS = require('cos-js-sdk-v5')
var cos = new COS({
  SecretId: 'AKIDRhhRv97pHTP4TcV8UaQ0JM9gwwgAOL2T',
  SecretKey: 'D9pEOHvJRJuGLAj25sOfgQu86nEPJxLS'
})
export default {
  name: 'Dashboard',
  components: {
    UploadImage
  },
  data() {
    return {
      value: 'https://example.com',
      size: 300
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  mounted() {
    this.$refs.fileRef.onchange = function(e) {
      const file = this.files[0]
      cos.uploadFile({
        Bucket: 'rzzt-1314109027', /* 填写自己的bucket，必须字段 */
        Region: 'ap-chengdu', /* 存储桶所在地域，必须字段 */
        Key: Date.now() + file.name, /* 存储在桶里的对象键（例如:1.jpg，a/b/test.txt，图片.jpg）支持中文，必须字段 */
        Body: file, // 上传文件对象
        SliceSize: 1024 * 1024 * 5,
        onProgress: function(progressDate) {
          console.log(JSON.stringify(progressDate))
        }
      }, function(err, data) {
        if (err) {
          console.log('上传失败', err)
        } else {
          console.log('上传成功', data)
        }
      })
    }
  }
}

</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
